{ open Parser }

rule token = parse
  [' ' '\t' '\r' '\n'] { token lexbuf }  (* Whitespace *)
| "/*"        { comment lexbuf }         (* Comments *)
| '('         { LPAREN }
| ')'         { RPAREN }
| '{'         { LBRACE }
| '}'         { RBRACE }
| "[["        { LMAP }
| "]]"        { RMAP }
| '['         { LARRAY }
| ']'         { RARRAY }
| ';'         { SEMI }
| ','         { COMMA }
| '+'         { PLUS }
| '-'         { MINUS }
| '*'         { TIMES }
| '/'         { DIVIDE }
| "<-"        { ASSIGN }
| "->"        { RASSIGN }
| '='         { EQ }
| "!="        { NEQ }
| '<'         { LT }
| '>'         { GT }
| "<="        { LEQ }
| ">="        { GEQ }
| '&'         { AND }
| '|'         { OR }
| '!'         { NOT }
| "if"        { IF }
| "then"      { THEN }
| "else"      { ELSE }
| "foreach"   { FOREACH }
| "while"     { WHILE }
| "return"    { RETURN }
| "break"     { BREAK }
| "end"       { END }
| "use"       { USE }
| "function"  { FUNCTION }
| "fun"       { FUNCTION }
| "boolean"   { BOOL }
| "integer"   { INT }
| "real"      { REAL }
| "string"    { STRING }
| "array"     { ARRAY }
| "map"       { MAP }
| "HtmlDoc"   { HTML }
| "in"        { IN }

| "TRUE"      { LITERAL_BOOL(true) }
| "FALSE"     { LITERAL_BOOL(false) }

| ['0'-'9']+'.'['0'-'9']* as lxm { LITERAL_REAL( float_of_string lxm )  }
| ['0'-'9']+ as lxm { LITERAL_INT(int_of_string lxm) }
| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
| '"' (['a'-'z' 'A'-'Z' '0'-'9' '_' ' ' '+' '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '-' '+' '=' '{' '[' '}' ']' '|' ';' ':' '<' ',' '.' '>' '/' '?' '`' '~']|"\\\""|"\\\\"|"\\\'")*'"'
       as lxm { LITERAL_STR(String.sub lxm 1 ((String.length lxm)-2)) }
| eof { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }

and comment = parse
  "*/" { token lexbuf }
| _    { comment lexbuf }

